/*
 *  Copyright 2007-2008 by Matthias Buch-Kromann <mbk.isv@cbs.dk>.
 *  *
 *  This file is part of the Open-source Dependency Toolkit (OSDT),
 *  see http://code.google.com/p/open-source-dependency-toolkit.
 *  
 *  The OSDT is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as 
 *  published by the Free Software Foundation, either version 3 of 
 *  the License, or (at your option) any later version.
 * 
 *  The OSDT is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General Public 
 *  License along with the OSDT in the files COPYING and COPYING.LESSER.
 *  If not, see http://www.gnu.org/licenses.
 */

package org.osdtsystem.values;

/**
 * A private feature encoding a feature coupled to a particular location.
 * The purpose of a private feature is to enable a particular location, eg, 
 * a view, to store feature-value pairs at particular nodes. But in order to
 * avoid name clashes, we need to have a unique feature name for each location.
 * @author Matthias Buch-Kromann <mbk.isv@cbs.dk>
 */
public class PrivateFeature extends AbstractFeature implements Feature {
    Location location;
    Feature feature;

    public PrivateFeature(Location location, Feature feature) {
        this.location = location;
        this.feature = feature;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PrivateFeature other = (PrivateFeature) obj;
        if (this.location != other.location && (this.location == null || !this.location.equals(other.location))) {
            return false;
        }
        if (this.feature != other.feature && (this.feature == null || !this.feature.equals(other.feature))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 83 * hash + (this.location != null ? this.location.hashCode() : 0);
        hash = 83 * hash + (this.feature != null ? this.feature.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean internalFeature() {
        return true;
    }

    @Override
    public String toString() {
        return feature.toString() + "[" + location.toString() + "]";
    }
    
    @Override
    public int compareTo(Object o) {
        Feature n = (Feature) o;
        return toString().compareTo(n.toString());
    }
}
